<?php
/**
 * ADICIONA USU&Aacute;RIO
 */

if(	isset($_POST['module']) && $_POST['module'] == 'user' && 
	isset($_POST['action']) && $_POST['action'] == 'add'){
	$usuario = new User();
	$usuario->set_username($_POST['username']);
	$usuario->set_name($_POST['name']);
	$usuario->set_password($_POST['password']);
	$usuario->set_email($_POST['email']);
	$usuario->set_avatar($_POST['avatar']);
	$usuario->new_user();
	$usuario->logar($_POST['username'],$_POST['password']);
	header("location:/home/p/home");
}

/**
 * ADICIONA SISTEMA
 */
if(	isset($_POST['module']) && $_POST['module'] == 'system' && 
	isset($_POST['action']) && $_POST['action'] == 'add'){
	$name 			= $_POST['name'];
	$description 	= $_POST['description'];
	addSystem($name,$description) 
		or die("Erro ao adicionar Sistema");
}
/**
 * ADICIONA SUPLEMENTO
 */
if(	isset($_POST['module']) && $_POST['module'] == 'supplement' && 
	isset($_POST['action']) && $_POST['action'] == 'add'){
	$name 			= $_POST['name'];
	$description 	= $_POST['description'];
	$idSystem 		= $_POST['idSystem'];
	addSupplement($name,$description, $idSystem) 
		or die("Erro ao adicionar Suplemento.");
}
/**
 * ADICIONA CR&Ocirc;NICA
 */
if(	isset($_POST['module']) && $_POST['module'] == 'chronicle' && 
	isset($_POST['action']) && $_POST['action'] == 'add'){
	$name 			= $_POST['name'];
	$description 	= $_POST['description'];
	$idStoryteller 	= $_POST['idStoryteller'];
	$idSupplement 	= $_POST['idSupplement'];
	$dtIni 			= isset($_REQUEST["dtIni"]) ? $_REQUEST["dtIni"] : "";
	$dtEnd 			= isset($_REQUEST["dtEnd"]) ? $_REQUEST["dtEnd"] : "";
	addChronicle($name,$description, $idStoryteller, $idSupplement, $dtIni, $dtEnd) 
		or die("Erro ao adicionar cr&ocirc;nica.");
}

/**
 * EDITA PERFIL
 */
if(	isset($_POST['module']) && $_POST['module'] == 'perfil' && 
	isset($_POST['action']) && $_POST['action'] == 'edit'){
	$usuario = new User();
	$usuario->getUser($_POST['id']);
	$usuario->set_name($_POST['name']);
	$usuario->set_email($_POST['email']);
	$usuario->set_avatar($_POST['avatar']);
	$usuario->save_user();
	header("location:/home/p/perfil");
}
?>